﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class CargoIProvider : IProvider<Cargo>
    { 
        private SMEntities db=new SMEntities();
        public int Delete(int Id)
        {
            Cargo entity=  db.Cargo.Find(Id);
            if(entity != null)
            {
                db.Cargo.Remove(entity);
               int  A=   db.SaveChanges();
                return A;
            }
            return 0;
        }

        public List<Cargo> GetAll()
        {
            return db.Cargo.ToList();
        }

        public int Insert(Cargo t)
        {
               db.Cargo.Add(t);
            int A= db.SaveChanges();
            return A;
        }

        public int Update(Cargo t)
        {
            Cargo entity = db.Cargo.FirstOrDefault(e => e.Id == t.Id);
            if(entity != null)
            {
                 // 修改实体属性值
            entity.Name = t.Name;
            entity.Tag = t.Tag;
            return          db.SaveChanges();
            }
            return 0;
        }
          public Cargo GetById(int Id)
        {
            Cargo entity=  db.Cargo.Find(Id);
            return entity;
        }
    }
}
